import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})

export class CommidityLabelManageService {

  serviceUrls = {
    queryGoodsListUrl: '/goods/list/page', // 查询商品List
    querySelectedGoodsListUrl: '/goods/getGoodsByIdList', // 查询已选商品List
    queryGoodsTypeTreeUrl: '/goodstypes/list', // 查询商品分类tree
    queryGoodsBrandUrl: '/coupon/goodsTypeAndBrand', // 查询指定品牌

    queryGoodsLabelListUrl: '/rechargeGoodsLabel/list', // 查询商品标签List
    queryGoodsLabelDetailsUrl: '/rechargeGoodsLabel/details', // 查询商品标签详情
    saveGoodsLabelUrl: '/rechargeGoodsLabel/save', // 新增商品标签
    updateGoodsLabelUrl: '/rechargeGoodsLabel/update' // 编辑商品标签
  }

  constructor(public httpClient: HttpClient) {}

  // 查询商品List
  getGoodsListData(params: any) {
    return this.httpClient.get(this.serviceUrls.queryGoodsListUrl, { params }).toPromise();
  }

  // 查询已选商品List
  getSelectedGoodsList(params: any) {
    return this.httpClient.post(this.serviceUrls.querySelectedGoodsListUrl, params).toPromise();
  }

  // 查询商品分类tree
  queryGoodsTypeTreeData() {
    return this.httpClient.get(this.serviceUrls.queryGoodsTypeTreeUrl).toPromise();
  }

  // 查询指定品牌
  queryGoodsBrandData() {
    return this.httpClient.get(this.serviceUrls.queryGoodsBrandUrl).toPromise();
  }

  // 查询商品标签List
  getGoodsLabelList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryGoodsLabelListUrl, params).toPromise();
  }

  // 查询商品标签详情
  getGoodsLabelDetailsData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryGoodsLabelDetailsUrl, params).toPromise();
  }

  /**
   * 新增 or 编辑 商品标签
   * @param params 
   * @param type 0：新增 1：编辑
   */
  addEditGoodsLabelData(params: any, type: number | string) {
    let url = type == 0 ? this.serviceUrls.saveGoodsLabelUrl : this.serviceUrls.updateGoodsLabelUrl;
    return this.httpClient.post(url, params).toPromise();
  }
}
